﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;
namespace IHISCETeim.BLL
{
    public class OJobController : BaseController
    {
        public static int Add(OJobInfo obj)
        {
            return OJobDAL.Add(obj);
        }
        public static bool Delete(string SerialNumber)
        {
            return OJobDAL.Delete(SerialNumber);
        }
        public static OJobInfo GetBySerialNumber(string SerialNumber)
        {
            return CBO.FillObject<OJobInfo>( OJobDAL.GetBySerialNumber(SerialNumber));
        }
        public static DataTableCollection GetPagination(string WhereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return OJobDAL.GetPagination(WhereSql, PageIndex, PageSize, Sort, ref  TotalCount);
        }
        public static bool Update(OJobInfo obj)
        {
            return OJobDAL.Update(obj);
        }
        public static bool UpdateIsSellStorage(int JobId, bool IsSellStorage)
        {
            return OJobDAL.UpdateIsSellStorage(JobId, IsSellStorage);
        }
        /// <summary>
        ///获取所有的作业内容
        /// </summary>
        /// <returns></returns>
        public static List<OJobContentInfo> GetALLJobContent()
        {
            return CBO.FillCollection<OJobContentInfo>( OJobDAL.GetALLJobContent());
        }

        public static DataTable GetALLJobContent2()
        {

            DataTable dt = DC.Get<DataTable>(OJobContentALL);
            if (dt == null)
            {
                dt = OJobDAL.GetALLJobContent2();
                DC.Add(OJobContentALL, dt);
            }
            return dt;
        }
        public static DataTable GetALLJobContent2(string key, int toprow)
        {
          
            DataTable dt = GetALLJobContent2();
            DataRow[] drs;
            if (string.IsNullOrEmpty(key))
                drs = dt.Select("");
            else
                drs = dt.Select("JobCode like '%" + key + "%' or JobTitle like '%" + key + "%'");
            if (drs.Count() <= 0)
                return null;
            dt = drs.Take(toprow).CopyToDataTable();
            return dt;

        }

        public static object GetReport(string mactype, string ItemType, string StateDate, string EndDate, string color)
        {
            return OJobDAL.GetReport(mactype, ItemType, StateDate, EndDate, color);
        }

        public static object GetCountByFiled(string FiledName)
        {
            return OJobDAL.GetCountByFiled(FiledName);
        }


        /// <summary>
        /// 保存目标
        /// </summary>
        /// <param name="JobGoalKey"></param>
        /// <param name="JobGoalValue"></param>
        public static void OJobGoal_Edit(string JobGoalKey, string JobGoalValue)
        {
            OJobDAL.OJobGoal_Edit(JobGoalKey, JobGoalValue);
        }
        /// <summary>
        /// 获取目标
        /// </summary>
        /// <param name="JobGoalKey"></param>
        /// <returns></returns>
        public static object OJobGoal_Get(string JobGoalKey)
        {
            return OJobDAL.OJobGoal_Get(JobGoalKey);
        }

        /// <summary>
        /// 验证机号对应的发动机号是否一致 返回空为一致，否则返回不一致信息
        ///@VTtype=1 来源是机器一览表
        ///@vtype=2 来源是完成检查书
        ///@vtype=3 来源是完检单
        /// </summary>
        /// <param name="SerialNumber"></param>
        /// <param name="EngineNumber"></param>
        /// <param name="VTtype"></param>
        /// <returns></returns>
        public static string CheckEngineNumber(string SerialNumber, string EngineNumber, int VTtype)
        {
            return OJobDAL.CheckEngineNumber(SerialNumber,EngineNumber, VTtype);
        }
    }
}
